#ifndef BOOKMARKMANAGER_H
#define BOOKMARKMANAGER_H

#include "Bookmark.h"

class CodeEditor;

namespace Bookmarks {

class BookmarkManager : public QObject
{
    Q_OBJECT

private:
    BookmarkManager();

public:
    explicit BookmarkManager(CodeEditor* editor);
    ~BookmarkManager();

    void updateBookmark(Bookmark* bookmark);
    void removeBookmark(Bookmark* bookmark);
    void removeAllBookmarks();
    Bookmark* findBookmark(const QString& fileName, int lineNumber);
    void addBookmark(Bookmark* bookmark, bool userSet = true);
    void addBookmark(const QString& s);

    enum State {
        NoBookmarks,
        HasBookmarks,
        HasBookmarksInDocument
    };

    State state() const;

public slots:
    void toggleBookmark();
    void toggleBookmark(const QString& fileName, int lineNumber);
    void nextInDocument();
    void prevInDocument();
    bool gotoBookmark(Bookmark* bookmark);

signals:
    void updateActions(int state);
    void currentIndexChanged(int);

private slots:
    void updateActionStatus();
    void loadBookmarks();

private:
    void documentPrevNext(bool next);

    static QString bookmarkToString(const Bookmark* bookmark);
    void saveBookmarks();

    typedef QMultiMap<QString, Bookmark*> FileNameBookmarksMap;
    typedef QMap<QString, FileNameBookmarksMap*> DirectoryFileBookmarksMap;

    DirectoryFileBookmarksMap _bookmarksMap;
    CodeEditor* _editor;
};

} // namespace Bookmarks

#endif // BOOKMARKMANAGER_H
